package com.ruoyi.match.controller;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.uuid.IdWorker;
import com.ruoyi.match.domain.MatchClass;
import com.ruoyi.match.domain.MatchEquipment;
import com.ruoyi.match.domain.MatchUserVo;
import com.ruoyi.match.service.IMatchClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Api(tags = "班级管理")
@RestController
@RequestMapping("/match/class")
public class MatchClassController extends BaseController
{
    @Autowired
    private IMatchClassService matchClassService;


//    @PreAuthorize("@ss.hasPermi('system:class:add')")
    @ApiImplicitParam(name = "className", value = "班级名称",dataType = "String",paramType = "body")
    @PostMapping("add")
    @ApiOperation("新增")
    public AjaxResult add(@RequestBody MatchClass className)
    {
        className.setId(IdUtils.randomUUID());
        return toAjax(matchClassService.insertMatchClass(className));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:class:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping("update")
    @ApiImplicitParam(name = "matchClass", value = "班级id 和name",dataType = "MatchClass",paramType = "body")
    @ApiOperation("修改班级")
    public AjaxResult edit(@RequestBody MatchClass matchClass)
    {
        return toAjax(matchClassService.updateMatchClass(matchClass));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('system:class:remove')")
    @ApiOperation("删除")
	@DeleteMapping("/{ids}")
    @ApiImplicitParam(name = "ids", value = "ids",dataType = "Integer",paramType = "path",allowMultiple = true)
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(matchClassService.deleteMatchClassByIds(ids));
    }

    @ApiOperation(value = "查训班级", notes = "查训班级")
    @GetMapping("getAllClass")
    public AjaxResult getAll(){
        List<MatchClass> list = matchClassService.selectMatchClassList(null);
        return AjaxResult.success(list);
    }
    @GetMapping("/fenyelist")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="pageNum" , value = "开始页码",required = false, defaultValue = "1",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name ="pageSize" , value = "每页显示的条目数",required = false,defaultValue = "10",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name ="name" , value = "班级名称",required = false,dataType = "String",paramType = "query"),

    })
    public TableDataInfo list(String name)
    {
         MatchClass matchClass=new MatchClass();
        matchClass.setName(name );
        startPage();
        List<MatchClass> list = matchClassService.selectMatchClassList(matchClass);
        return getDataTable(list);
    }

}
